### Make up data to plot

data2plot = data.frame(elev = c(1,1,2,2,3,3), x=c(2,4,5,3,7,4), y=c(1,6,8,3.2,6,5))

### Create vectors of pchs and colors

pchs = c(1,2,3)

ltys = c(4,5,6)

cols = colorRampPalette(c('blue','green','white'))

# Position tracker

i=1

for (elev in unique(data2plot$elev))

	{
	
	t2plot = data2plot[which(data2plot$elev==elev),] # Subset data
	
	lm1 = lm(t2plot$y~t2plot$x)
	 
	plot(t2plot$x,t2plot$y,pch=pchs[i],col=cols(3)[i],lty=ltys[i], ask=T, type='n') # Plot data with specific color and character
	
	points(t2plot$x,t2plot$y)
	
	legend('topleft',legend = c('Summarized Microclimate Model',paste('Adj. r^2 ',substr(summary.lm(lm1)[9],1,4),sep=''),paste('Slope ',round(lm1$coefficients[2],2),sep=''),paste('Intercept ',round(lm1$coefficients[1],2),sep='')),text.col=c('black','red','blue','blue'), pch=pchs[i], bty='n')
	
	i=i+1 # Adjust position tracker
	
	}
	
# Close loop

# For putting a legend in one plot only 

if(elev==3)
	
	{
	
	legend('topleft',legend = c('Summarized Microclimate Model',paste('Adj. r^2 ',substr(summary.lm(lm1)[9],1,4),sep=''),paste('Slope ',round(lm1$coefficients[2],2),sep=''),paste('Intercept ',round(lm1$coefficients[1],2),sep='')),text.col=c('black','red','blue','blue'), pch=pchs[i], bty='n')
	
	}
	
	
	
	
	

	